# coding=utf-8
import unittest
from .. import HebrewWord

class TestHebrewWord(unittest.TestCase):
  '''Unit tests for the HebrewWord class.'''

  def test_vav_dagesh_kamatz(self):
    '''{vav, dagesh} followed by a vowel (kamatz).'''
    test = HebrewWord.parse(u'\u05d0\u05b4\u05d5\u05bc\u05b8\u05e9\u05c1\u05b5\u05e2\u05b7')
    expected = ['aleph', 'chirik', 'vav', 'dagesh', 'kamatz',
      'shin', 'tzerei', 'ayin', 'patach-gnuvah']
    self.assertEqual(test, expected)

  def test_vav_dagesh_cholom_malei(self):
    '''{vav, dagesh} followed by a vowel (cholom-malei).'''
    test = HebrewWord.parse(u'וּלְצַוּוֹת')
    expected = ['shuruk', 'lamed', "sh'va", 'tzadi', 'patach', 'vav',
      'dagesh', 'cholom-malei', 'saf']
    self.assertEqual(test, expected)

  def test_shuruk_end(self):
    '''Expected to follow default branch at the end of a word.'''
    test = HebrewWord.parse(u'וַיּוֹרֵהוּ')
    expected = ['vav', 'patach', 'yud', 'dagesh', 'cholom-malei', 'reish', 
      'tzerei', 'hey', 'shuruk']
    self.assertEqual(test, expected)

  def test_sin_dagesh_sin(self):
    '''Special test for the name of Yissacher'''
    test = HebrewWord.parse(u'לְיִשָּׂשכָר')
    expected = ['lamed', "sh'va", 'yud', 'chirik', 'sin', 'dagesh', 'kamatz', 
      'sin', 'chaf', 'kamatz', 'reish']
    self.assertEqual(test, expected)

  def test_saf_dagesh(self):
    '''Expected to detect taf/saf correctly.'''
    test = HebrewWord.parse(u'נֶעְתַּם')
    expected = ['nun', 'segol', 'ayin', "sh'va", 'taf', 'patach', 'mem-sofit']
    self.assertEqual(test, expected)
    
  def test_patach_gnuvah(self):
    '''Expected to detect patach gnuvah at the end of a word.'''
    test = HebrewWord.parse(u'בָּטֻחַ')
    expected = ['bet', 'kamatz', 'tet', 'kubutz', 'chet', 'patach-gnuvah']
    self.assertEqual(test, expected)
  
  def test_hashem_name(self):
    '''Expected to detect names of HaShem.'''
    self.assertTrue(HebrewWord.hashem_name(u'אֱלֹהִים'))
    self.assertTrue(HebrewWord.hashem_name(u'אֱלוֹהֵי'))
    self.assertTrue(HebrewWord.hashem_name(u'אֱלוֹהַי'))
    self.assertTrue(HebrewWord.hashem_name(u'אֵל'))
    self.assertFalse(HebrewWord.hashem_name(u'אֵלַי'))
    self.assertTrue(HebrewWord.hashem_name(u'בֵאלֹהִים'))

if __name__ == '__main__': unittest.main()